﻿using System.Threading.Tasks;
using Thinker.SignChannel.Results;
using Volo.Abp.SettingManagement;
using static Thinker.SignChannel.Settings.SignChannelSettings;

namespace Thinker.SignChannel.Settings;

public class SettingAppService(ISettingManager settingManager)
    : SignChannelAppService, ISettingAppService
{
    public async Task<SettingDto> GetAsync()
    {
        var appTitle = await settingManager.GetOrNullGlobalAsync(AppTitle);
        var style = await settingManager.GetOrNullGlobalAsync(ResultCreateStyle);
        var resultCreateStyle = style.FromSetting();
        return new SettingDto
        {
            AppTitle = appTitle,
            ResultCreateStyle = resultCreateStyle
        };
    }

    public async Task<SettingDto> UpdateAsync(SettingDto input)
    {
        await settingManager.SetGlobalAsync(AppTitle, input.AppTitle);
        await settingManager.SetGlobalAsync(ResultCreateStyle, input.ResultCreateStyle.ToSetting());
        return await GetAsync();
    }
}